(function($, undefined) {
    $.jsonToString = function(obj) {
        var THIS = this;
        switch (typeof (obj)) {
        case 'string':
            return "'" + obj.replace(/(["\\])/g, '\\$1') + "'";
        case 'array':
            return '[' + obj.map(THIS.jsonToString).join(',') + ']';
        case 'object':
            if (obj instanceof Array) {
                var strArr = [];
                var len = obj.length;
                for ( var i = 0; i < len; i++) {
                    strArr.push(THIS.jsonToString(obj[i]));
                }
                return '[' + strArr.join(',') + ']';
            } else if (obj == null) {
                return 'null';

            } else {
                var string = [];
                for ( var property in obj)
                    string.push(THIS.jsonToString(property) + ':' + THIS.jsonToString(obj[property]));
                return '{' + string.join(',') + '}';
            }
        case 'number':
            return obj;
        case 'false':
            return obj;
        }
    };

    $.myAjax = function(config) {
        $.ajax(config);
    };

    $.getGender = function(gender) {
        switch (gender) {
        case 'F':
            return '女';
        case 'M':
            return '男';
        default:
            return '性别保密';
        }
    };

    $.getAge = function(birthday) {
        var date = new Date();
        year = date.getFullYear();
        month = date.getMonth();
        day = date.getDate();
        
        birthday = birthday.split(" ")[0].split("-");
        var birthYear = birthday[0];
        var birthMonth = birthday[1];
        var birthDate = birthday[2];
        if(birthMonth < month){
            return year - birthYear - 1;
        } else if(birthMonth == month){
            if(birthDate < day){
                return year -birthYear - 1;
            } else {
                return year -birthYear;
            }
        } else {
            return year - birthYear;
        }
        return 0;
    };
    
    $.getMarryStatus = function(marryStatus){
        switch(marryStatus){
        case 1:
            return '未婚';
        case 2:
            return '离异';
        case 3:
            return '丧偶';
        default:
            return '保密'
        }
    };
    
    $.getDegree = function(degree){
        switch(degree){
        case 1:
            return '高中';
        case 2:
            return '大专';
        case 3:
            return '本科';
        case 4:
            return '硕士';
        case 5:
            return '博士';
        default:
            return '学历保密';
        }
    };
    
    $.getIncome = function(income){
        switch(income){
        case 1:
            return '1000元以下';
        case 2:
            return '1001-2000元';
        case 3:
            return '2001-3000元';
        case 4:
            return '3001-5000元';
        case 5:
            return '5001-8000元';
        case 6:
            return '8001-10000元';
        case 7:
            return '10001-20000元';
        case 8:
            return '20001-50000元';
        case 9:
            return '50000元以上';
        default:
            return '收入保密';
        }
    }
    
    $.confirm = function(config){
        var $self = this;
        var htm = '';
        htm += '<div style="width:300px;height:150px;">';
        htm += '    <p style="text-align:center; height:100px;line-height:100px;font-size:14px;">' + config.msg + '</p>';
        if(config.buttons && config.buttons.length > 0){
            htm += '    <div class="button-wrap" style="text-align:center;padding:15px;font-size:14px;height:20px; line-height:20px;">';
            for(var i=0; i<config.buttons.length; i++){
                htm += '<a href="javascript:void(0);" style="margin:0px 10px;">' + config.buttons[i].name + '</a>';
            }
            htm += '    </div>';
        }
        htm += '</div>';
        $self.dlg = $(htm).rioDialog({
        });
        $('.button-wrap a').each(function(index, item){
            $(item).bind('mousedown.rio', function(event){
                if(config.buttons[index].click){
                    config.buttons[index].click.call($self);
                }
            });
        });
    };
    $.confirm.prototype = {
            destroy : function(){
                this.dlg.rioDialog('destroy');
            }
    }
})(jQuery);